﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using DPFP;
using DevExpress.Xpo.Metadata;

namespace TransLogger.Module
{
    public class FingerprintConverter : ValueConverter
    {
        public override object ConvertToStorageType(object value)
        {
            if (value == null)
            {
                return null;
            }

            var tp = (Template)value;
            using (var mem = new MemoryStream())
            {
                tp.Serialize(mem);
                return mem.ToArray();
            }

        }

        public override object ConvertFromStorageType(object value)
        {
            if (value == null)
            {
                return null;
            }

            var bytes = (byte[])value;
            var tp = new Template();
            tp.DeSerialize(bytes);
            return tp;
        }

        public override Type StorageType
        {
            get { return typeof(byte[]); }
        }
    }
}
